package cn.tedu.charging.device.controller;

import cn.tedu.charging.common.pojo.JsonResult;
import cn.tedu.charging.common.pojo.param.GunStatusUpdateParam;
import cn.tedu.charging.common.pojo.vo.StationInfoVO;
import cn.tedu.charging.device.pojo.param.StationNearQuery;
import cn.tedu.charging.device.service.DeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "设备模块")
@Slf4j
@RestController
@RequestMapping("device")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    /**
     * 附近充电站
     * @return
     */
    @ApiOperation("附近充电站")
    @PostMapping("/station/near")
    public JsonResult<List<StationInfoVO>>
                            getNearStation(@RequestBody StationNearQuery query){
        log.debug("附近充电站-入参:经度{},维度{},距离{}",
                query.getLng(), query.getLat(),query.getRadius());
        List<StationInfoVO> stationInfos =
                deviceService.getNearStation(query);
        return JsonResult.ok(stationInfos, "获取附近充电站成功");
    }

    @ApiOperation("获取场站信息")
    @GetMapping("/station/info/{gunId}")
    public JsonResult<StationInfoVO> getStationInfo(@PathVariable("gunId") Integer gunId) {
        log.debug("获取场站信息-入参:{}",gunId);
        StationInfoVO stationInfo =
                deviceService.getStationInfo(gunId);
        log.debug("获取场站信息-入参:{},出参:{}",gunId,stationInfo);
        JsonResult<StationInfoVO> result = JsonResult.ok(stationInfo, "获取场站信息成功");
        log.debug("获取场站信息-入参:{},出参:{}",gunId,result);
        return result;
    }

    @ApiOperation("更新枪状态")
    @PostMapping("/station/gun/status/update")
    public JsonResult<Boolean> updateGunStatus(@RequestBody GunStatusUpdateParam param) {
        log.debug("更新枪状态-入参:{}",param);
        Boolean success = deviceService.updateGunStatus(param);
        log.debug("更新枪状态-入参:{},出参:{}",param,success);
        JsonResult<Boolean> result =
                JsonResult.ok(success, "更新枪状态成功");
        log.debug("更新枪状态-入参:{},出参:{}",param,result);
        return result;
    }
}
